#!/bin/bash

# Check params
if [ $# -lt 1 ]; then
 echo "Usage: $0 <interface name>"
 exit
fi

#Store interface name
IF="$1"

# Check for warning.
if [ ! -f ../interfaces/${IF}/${IF}Client.hpp ]; then
 echo "Warning: No such interface exists under MaCI/interfaces: '${IF}'!"
fi

# create dir.
if [ ! -e ./$IF ]; then
 mkdir $IF
 if [ ! -d $IF ]; then
   echo "Failed to create directory './${IF}'. Cannot proceed."
   exit
 fi
else
 echo "Error: Directory './${IF}' already exists, will not proceed!"
 exit
fi

# Copy Dummy code.
UPPERNAME=`echo ${IF} | tr "[:lower:]" "[:upper:]"`

echo "Converting example source."
cat Dummy/DummyClientExample.cpp | sed "s/Dummy/${1}/g" > tmp.$$$$
cat tmp.$$$$ | sed "s/DUMMY/${UPPERNAME}/" > ${IF}/${IF}ClientExample.cpp
rm tmp.$$$$


echo "Converting Makefile"
cat Makefile.forsubdirs | sed "s/PlaceHolder/${1}/g" > Makefile.forsubdirs.$$$$
cat Makefile.forsubdirs.$$$$ | sed "s/PLACEHOLDER/${UPPERNAME}/g" > ${IF}/Makefile
rm Makefile.forsubdirs.$$$$

echo "Complete. New interface example dummy created in subdirectory '${IF}'"


# Copy Makefile
